]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
dnd: Adapt to Clutter cursors
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 5 Nov 2025 11:39:16 +0000 (12:39 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 19 Jan 2026 09:33:30 +0000 (09:33 +0000)
Set the expected drag and drop cursor through the grab actor instead
of globally.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3952>

js/ui/dnd.js

index cf89b61d21047f63ba718e3de5b430e44d47704b..a0096a0b0b5039dc6288909eb7c97c347f6b69cb 100644 (file)
@@ -1,6 +1,5 @@
 import Clutter from 'gi://Clutter';
 import GLib from 'gi://GLib';
-import Meta from 'gi://Meta';
 import Shell from 'gi://Shell';
 import St from 'gi://St';
 import * as Signals from '../misc/signals.js';
@@ -24,9 +23,9 @@ export const DragMotionResult = {
 };
 
 const DRAG_CURSOR_MAP = {
-    0: Meta.Cursor.NO_DROP,
-    1: Meta.Cursor.COPY,
-    2: Meta.Cursor.MOVE,
+    0: Clutter.CursorType.NO_DROP,
+    1: Clutter.CursorType.COPY,
+    2: Clutter.CursorType.MOVE,
 };
 
 export const DragDropResult = {
@@ -132,6 +131,10 @@ class _Draggable extends Signals.EventEmitter {
         this._sprite = null;
     }
 
+    _updateCursor(cursorType) {
+        global.stage.get_grab_actor()?.set_cursor_type(cursorType);
+    }
+
     _gestureRecognized() {
         const pointBeginEvent = this._dndGesture.get_point_begin_event();
         [this._dragStartX, this._dragStartY] = pointBeginEvent.get_coords();
@@ -149,7 +152,7 @@ class _Draggable extends Signals.EventEmitter {
             return;
 
         this.emit('drag-begin', time);
-        global.display.set_cursor(Meta.Cursor.NO_DROP);
+        this._updateCursor(Clutter.CursorType.NO_DROP);
 
         this._dragX = stageX;
         this._dragY = stageY;
@@ -333,7 +336,7 @@ class _Draggable extends Signals.EventEmitter {
             if (motionFunc) {
                 const result = motionFunc(dragEvent);
                 if (result !== DragMotionResult.CONTINUE) {
-                    global.display.set_cursor(DRAG_CURSOR_MAP[result]);
+                    this._updateCursor(DRAG_CURSOR_MAP[result]);
                     dragEvent.targetActor.disconnect(targetActorDestroyHandlerId);
                     return GLib.SOURCE_REMOVE;
                 }
@@ -354,13 +357,13 @@ class _Draggable extends Signals.EventEmitter {
                     targY,
                     0);
                 if (result !== DragMotionResult.CONTINUE) {
-                    global.display.set_cursor(DRAG_CURSOR_MAP[result]);
+                    this._updateCursor(DRAG_CURSOR_MAP[result]);
                     return GLib.SOURCE_REMOVE;
                 }
             }
             target = target.get_parent();
         }
-        global.display.set_cursor(Meta.Cursor.NO_DROP);
+        this._updateCursor(Clutter.CursorType.NO_DROP);
         return GLib.SOURCE_REMOVE;
     }
 
@@ -440,7 +443,7 @@ class _Draggable extends Signals.EventEmitter {
                         }
                     }
 
-                    global.display.set_cursor(Meta.Cursor.DEFAULT);
+                    this._updateCursor(Clutter.CursorType.DEFAULT);
                     this.emit('drag-end', event.get_time(), true);
                     this._dragComplete();
                     return;
@@ -515,7 +518,7 @@ class _Draggable extends Signals.EventEmitter {
         this._animationInProgress = false;
         this._dragComplete();
 
-        global.display.set_cursor(Meta.Cursor.DEFAULT);
+        this._updateCursor(Clutter.CursorType.DEFAULT);
     }
 
     _onAnimationComplete(eventTime) {
@@ -595,7 +598,7 @@ class _Draggable extends Signals.EventEmitter {
         this.emit('drag-cancelled', eventTime);
 
         if (!this._dragActor) {
-            global.display.set_cursor(Meta.Cursor.DEFAULT);
+            this._updateCursor(Clutter.CursorType.DEFAULT);
             this._dragComplete();
             this.emit('drag-end', eventTime, false);
             if (!this._dragOrigParent && this._dragActor)